主页接口逻辑

chengzhenyu лет %!s(int64=8): %!d(string=назад)
Родитель
Сommit
4a8bec5157

+ 4 - 6
app/src/main/java/ai/pai/client/activity/MainActivity.java

@@ -33,7 +33,6 @@ import com.android.views.indicators.SpringBar;
33 33
 
34 34
 import java.io.File;
35 35
 
36
-import ai.pai.client.BuildConfig;
37 36
 import ai.pai.client.R;
38 37
 import ai.pai.client.beans.GroupInfo;
39 38
 import ai.pai.client.db.DBService;
@@ -44,7 +43,6 @@ import ai.pai.client.services.GroupService;
44 43
 import ai.pai.client.services.MyLocationService;
45 44
 import ai.pai.client.utils.Constants;
46 45
 import ai.pai.client.utils.PhotoLoader;
47
-import ai.pai.client.utils.UrlContainer;
48 46
 import ai.pai.client.views.GroupSelectPopup;
49 47
 import ai.pai.client.views.PersonInfoPopup;
50 48
 
@@ -100,7 +98,7 @@ public class MainActivity extends AppCompatActivity
100 98
     protected void onResume() {
101 99
         super.onResume();
102 100
         callGuideBtn.setVisibility(TextUtils.isEmpty(Preferences.getInstance(this).getTourGuidePhone()) ? View.INVISIBLE : View.VISIBLE);
103
-        if(Preferences.getInstance(this).isTourMode()|| BuildConfig.DEBUG){
101
+        if(Preferences.getInstance(this).isTourMode()){
104 102
             Intent intent = new Intent(this, MyLocationService.class);
105 103
             intent.putExtra("command",MyLocationService.COMMAND_START_LOCATION);
106 104
             startService(intent);
@@ -121,9 +119,6 @@ public class MainActivity extends AppCompatActivity
121 119
     @Override
122 120
     protected void onDestroy() {
123 121
         super.onDestroy();
124
-        Intent intent = new Intent(this, MyLocationService.class);
125
-        intent.putExtra("command",MyLocationService.COMMAND_DESTROY_LOCATION);
126
-        startService(intent);
127 122
     }
128 123
 
129 124
     @Override
@@ -349,6 +344,9 @@ public class MainActivity extends AppCompatActivity
349 344
     public void onCommandCommitSuccess(int command, Object response) {
350 345
         if(command == GroupService.GroupCommand.COMMAND_JOIN_GUIDE_GROUP){
351 346
             Preferences.getInstance(this).setTourMode(true);
347
+            Intent intent = new Intent(this, MyLocationService.class);
348
+            intent.putExtra("command",MyLocationService.COMMAND_START_LOCATION);
349
+            startService(intent);
352 350
         }
353 351
         if (command == GroupService.GroupCommand.COMMAND_JOIN_GROUP||command == GroupService.GroupCommand.COMMAND_JOIN_GUIDE_GROUP) {
354 352
             GroupInfo info = (GroupInfo) response;

+ 8 - 0
app/src/main/java/ai/pai/client/db/Preferences.java

@@ -51,6 +51,14 @@ public class Preferences {
51 51
         return mPrefs.getString("tour_phone",NullStr);
52 52
     }
53 53
 
54
+    public void setGatherTime(long gatherTime){
55
+        mPrefs.edit().putLong("gatherTime",gatherTime).commit();
56
+    }
57
+
58
+    public long getGatherTime(){
59
+        return mPrefs.getLong("gatherTime",0);
60
+    }
61
+
54 62
     public boolean isTourMode(){
55 63
         return mPrefs.getBoolean("isTourMode",false);
56 64
     }

+ 38 - 29
app/src/main/java/ai/pai/client/fragments/TabRecentPhotoFragment.java

@@ -1,12 +1,14 @@
1 1
 package ai.pai.client.fragments;
2 2
 
3 3
 import android.content.Context;
4
+import android.content.Intent;
4 5
 import android.os.AsyncTask;
5 6
 import android.os.Bundle;
6 7
 import android.support.v4.widget.SwipeRefreshLayout;
7 8
 import android.support.v7.widget.DefaultItemAnimator;
8 9
 import android.support.v7.widget.RecyclerView;
9 10
 import android.support.v7.widget.StaggeredGridLayoutManager;
11
+import android.text.TextUtils;
10 12
 import android.view.LayoutInflater;
11 13
 import android.view.View;
12 14
 import android.view.ViewGroup;
@@ -15,6 +17,7 @@ import android.widget.Toast;
15 17
 
16 18
 import com.android.common.executors.ThreadExecutor;
17 19
 import com.android.common.utils.LogHelper;
20
+import com.android.common.utils.TimeUtils;
18 21
 import com.android.views.banner.CBViewHolderCreator;
19 22
 import com.android.views.banner.ConvenientBanner;
20 23
 import com.android.views.banner.Holder;
@@ -30,13 +33,13 @@ import java.util.ArrayList;
30 33
 import java.util.Arrays;
31 34
 import java.util.HashMap;
32 35
 
33
-import ai.pai.client.BuildConfig;
34 36
 import ai.pai.client.R;
35 37
 import ai.pai.client.adapter.RecentPhotoStaggeredAdapter;
36 38
 import ai.pai.client.beans.BannerBean;
37 39
 import ai.pai.client.beans.GroupPhotoItem;
38 40
 import ai.pai.client.db.DBService;
39 41
 import ai.pai.client.db.Preferences;
42
+import ai.pai.client.services.MyLocationService;
40 43
 import ai.pai.client.utils.HttpPostTask;
41 44
 import ai.pai.client.utils.UrlContainer;
42 45
 import ai.pai.client.views.FullScreenImgPopup;
@@ -58,15 +61,8 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh
58 61
     private static  final int num = 10;
59 62
 
60 63
     private ConvenientBanner banner;
61
-    private ArrayList<BannerBean> bannerBeanList;
62 64
 
63
-    private String[] images = {"http://img2.imgtn.bdimg.com/it/u=3093785514,1341050958&fm=21&gp=0.jpg",
64
-            "http://img2.3lian.com/2014/f2/37/d/40.jpg",
65
-            "http://img2.3lian.com/2014/f2/37/d/39.jpg",
66
-            "http://www.8kmm.com/UploadFiles/2012/8/201208140920132659.jpg",
67
-            "http://f.hiphotos.baidu.com/image/h%3D200/sign=1478eb74d5a20cf45990f9df460b4b0c/d058ccbf6c81800a5422e5fdb43533fa838b4779.jpg",
68
-            "http://f.hiphotos.baidu.com/image/pic/item/09fa513d269759ee50f1971ab6fb43166c22dfba.jpg"
69
-    };
65
+    private String[] images = new String[2];
70 66
 
71 67
     @Override
72 68
     public void onCreate( Bundle savedInstanceState) {
@@ -122,24 +118,9 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh
122 118
     }
123 119
 
124 120
     private void fetchTourInfo(){
125
-        if(!Preferences.getInstance(getActivity()).isTourMode() && !BuildConfig.DEBUG){
126
-            return;
127
-        }
128 121
         if(fetchTourInfoTask!=null && fetchTourInfoTask.getStatus()== AsyncTask.Status.RUNNING){
129 122
             return;
130 123
         }
131
-        if(BuildConfig.DEBUG){
132
-            Preferences.getInstance(getActivity()).setTourGuidePhone("13811443340");
133
-            bannerBeanList = new ArrayList<>();
134
-            for(int k =0;k<6;k++){
135
-                BannerBean bean = new BannerBean();
136
-                bean.title = "title"+k;
137
-                bean.url = images[k];
138
-                bannerBeanList.add(bean);
139
-            }
140
-            initBanner();
141
-            return;
142
-        }
143 124
         HashMap<String,String> params = new HashMap<String,String>();
144 125
         String userId = Preferences.getInstance(getActivity()).getUserId();
145 126
         if(userId.length()==0){
@@ -156,8 +137,23 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh
156 137
                     JSONObject json = new JSONObject(response);
157 138
                     int status = json.getInt("status");
158 139
                     if(status == 200){
159
-                        JSONObject info = json.getJSONObject("data");
160
-
140
+                        JSONObject data = json.getJSONObject("data");
141
+                        String groupId = data.getString("group_id");
142
+                        if(!TextUtils.isEmpty(groupId)){
143
+                            Preferences.getInstance(context).setTourMode(true);
144
+                            JSONObject group = data.getJSONObject("group");
145
+                            String phone = group.getString("phone");
146
+                            Preferences.getInstance(context).setTourGuidePhone(phone);
147
+                            String gatherTimeStr = group.getString("gather_at");
148
+                            Preferences.getInstance(context).setGatherTime(TimeUtils.getStandardTimeInMiliSec(gatherTimeStr));
149
+                            JSONObject banners = group.getJSONObject("banners");
150
+                            images[0] = banners.getString("attentions");
151
+                            images[1] = banners.getString("schedules");
152
+                        }else{
153
+                            Preferences.getInstance(context).setTourMode(false);
154
+                            Preferences.getInstance(context).setTourGuidePhone("");
155
+                            Preferences.getInstance(context).setGatherTime(0);
156
+                        }
161 157
                         return true;
162 158
                     }
163 159
                 }catch (Exception e){
@@ -174,6 +170,16 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh
174 170
             @Override
175 171
             protected void onPostSuccess(Context context) {
176 172
                 super.onPostSuccess(context);
173
+                initBanner();
174
+                if(Preferences.getInstance(context).isTourMode()){
175
+                    Intent intent = new Intent(context, MyLocationService.class);
176
+                    intent.putExtra("command",MyLocationService.COMMAND_START_LOCATION);
177
+                    context.startService(intent);
178
+                }else{
179
+                    Intent intent = new Intent(context, MyLocationService.class);
180
+                    intent.putExtra("command",MyLocationService.COMMAND_DESTROY_LOCATION);
181
+                    context.startService(intent);
182
+                }
177 183
             }
178 184
         };
179 185
         fetchTourInfoTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.TOUR_INFO_URL);
@@ -181,7 +187,12 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh
181 187
     }
182 188
 
183 189
     private void initBanner(){
190
+        if(TextUtils.isEmpty(images[0]) && TextUtils.isEmpty(images[1])){
191
+            banner.setVisibility(View.GONE);
192
+            return;
193
+        }
184 194
         banner.setVisibility(View.VISIBLE);
195
+
185 196
         banner.setPages(new CBViewHolderCreator<NetworkImageHolderView>() {
186 197
             @Override
187 198
             public NetworkImageHolderView createHolder() {
@@ -219,7 +230,6 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh
219 230
             protected void onPreExecute() {
220 231
                 super.onPreExecute();
221 232
                 scrollListener.setLoading(true);
222
-//                swipeRefreshLayout.setRefreshing(true);
223 233
             }
224 234
 
225 235
             @Override
@@ -293,14 +303,13 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh
293 303
 
294 304
     @Override
295 305
     public void onItemClick(int position) {
296
-        new FullScreenImgPopup(getActivity(),bannerBeanList.get(position).url).showPopupWindow();
306
+        new FullScreenImgPopup(getActivity(),images[position]).showPopupWindow();
297 307
     }
298 308
 
299 309
     public class NetworkImageHolderView implements Holder<String> {
300 310
         private ImageView imageView;
301 311
         @Override
302 312
         public View createView(Context context) {
303
-            //你可以通过layout文件来创建,也可以像我一样用代码创建,不一定是Image,任何控件都可以进行翻页
304 313
             imageView = new ImageView(context);
305 314
             imageView.setScaleType(ImageView.ScaleType.FIT_XY);
306 315
             return imageView;

+ 4 - 39
app/src/main/java/ai/pai/client/services/MyLocationService.java

@@ -71,13 +71,7 @@ public class MyLocationService extends Service {
71 71
         destroyLocation();
72 72
     }
73 73
 
74
-    /**
75
-     * 初始化定位
76
-     *
77
-     * @since 2.8.0
78
-     * @author hongming.wang
79
-     *
80
-     */
74
+
81 75
     private void initLocation(){
82 76
         if(locationClient!=null){
83 77
             return;
@@ -91,12 +85,7 @@ public class MyLocationService extends Service {
91 85
         status = 0;
92 86
     }
93 87
 
94
-    /**
95
-     * 默认的定位参数
96
-     * @since 2.8.0
97
-     * @author hongming.wang
98
-     *
99
-     */
88
+
100 89
     private AMapLocationClientOption getDefaultOption(){
101 90
         AMapLocationClientOption mOption = new AMapLocationClientOption();
102 91
         mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式
@@ -112,9 +101,6 @@ public class MyLocationService extends Service {
112 101
         return mOption;
113 102
     }
114 103
 
115
-    /**
116
-     * 定位监听
117
-     */
118 104
     AMapLocationListener locationListener = new AMapLocationListener() {
119 105
         @Override
120 106
         public void onLocationChanged(AMapLocation loc) {
@@ -125,13 +111,6 @@ public class MyLocationService extends Service {
125 111
     };
126 112
 
127 113
 
128
-    /**
129
-     * 开始定位
130
-     *
131
-     * @since 2.8.0
132
-     * @author hongming.wang
133
-     *
134
-     */
135 114
     private void startLocation(){
136 115
         if(status==1){
137 116
             return;
@@ -144,13 +123,6 @@ public class MyLocationService extends Service {
144 123
         status = 1;
145 124
     }
146 125
 
147
-    /**
148
-     * 停止定位
149
-     *
150
-     * @since 2.8.0
151
-     * @author hongming.wang
152
-     *
153
-     */
154 126
     private void stopLocation(){
155 127
         if(status == 2){
156 128
             return;
@@ -160,13 +132,6 @@ public class MyLocationService extends Service {
160 132
         status = 2;
161 133
     }
162 134
 
163
-    /**
164
-     * 销毁定位
165
-     *
166
-     * @since 2.8.0
167
-     * @author hongming.wang
168
-     *
169
-     */
170 135
     private void destroyLocation(){
171 136
         if (null != locationClient) {
172 137
             locationClient.onDestroy();
@@ -184,7 +149,7 @@ private void reportLocationWhenTourMode(double lat, double lon){
184 149
     repeatTime = 0;
185 150
     lastLat = lat;
186 151
     lastLon = lon;
187
-    if(Preferences.getInstance(this).isTourMode()|| BuildConfig.DEBUG){
152
+    if(Preferences.getInstance(this).isTourMode()){
188 153
         HashMap<String,String> params = new HashMap<String,String>();
189 154
         String userId = Preferences.getInstance(this).getUserId();
190 155
         if(userId.length()==0){
@@ -194,7 +159,7 @@ private void reportLocationWhenTourMode(double lat, double lon){
194 159
         params.put("lon",String.valueOf(lon));
195 160
         params.put("lat",String.valueOf(lat));
196 161
         new HttpPostTask(this,params).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.GEO_LOCATION_URL);
197
-        LogHelper.d("czy","reportLocationWhenTourMode lat = "+lat+"lon="+lon);
162
+        LogHelper.dfile("czy","上报经纬度位置 lat = "+lat+"lon="+lon);
198 163
     }
199 164
 }
200 165
 

+ 1 - 1
app/src/main/java/ai/pai/client/utils/UrlContainer.java

@@ -84,5 +84,5 @@ public class UrlContainer {
84 84
 
85 85
     public static final String GEO_LOCATION_URL = HOST_URL+"geo/submit";
86 86
     //TODO
87
-    public static final String TOUR_INFO_URL = HOST_URL +"tg/info";
87
+    public static final String TOUR_INFO_URL = HOST_URL +"pai2/tginfo";
88 88
 }

+ 1 - 1
common/src/main/java/com/android/common/utils/LogHelper.java

@@ -137,7 +137,7 @@ class FileLog {
137 137
 
138 138
     public FileLog() throws RuntimeException, IOException {
139 139
         File sdcard = new File(SD_CARD);
140
-        String fileName = "上传测试"+new SimpleDateFormat("MM-dd-HH-mm").format(new Date()) + ".log";
140
+        String fileName = "paiai-"+new SimpleDateFormat("MM-dd-HH-mm").format(new Date()) + ".log";
141 141
         File logFile = new File(LOG_PATH+fileName);
142 142
 
143 143
         if (!sdcard.exists()) {

+ 12 - 0
common/src/main/java/com/android/common/utils/TimeUtils.java

@@ -1,6 +1,7 @@
1 1
 package com.android.common.utils;
2 2
 
3 3
 import java.text.DateFormat;
4
+import java.text.ParseException;
4 5
 import java.text.SimpleDateFormat;
5 6
 import java.util.Date;
6 7
 import java.util.TimeZone;
@@ -53,6 +54,17 @@ public class TimeUtils {
53 54
         return utc2Local(utcTime, "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd HH:mm");
54 55
     }
55 56
 
57
+    public static long getStandardTimeInMiliSec(String utcTime){
58
+        long time = 0;
59
+        String standardTimeStr = getStandardTime(utcTime);
60
+        try {
61
+            Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(standardTimeStr);
62
+            time = date.getTime();
63
+        } catch (ParseException e) {
64
+            e.printStackTrace();
65
+        }
66
+        return time;
67
+    }
56 68
 
57 69
     public static String getFormattedTime(String utcTime) {
58 70
         String formattedTime = utc2Local(utcTime, "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd HH:mm");